package org.csu.mypetstore.persistence;
//this is completed
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.mypetstore.domain.Product;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProductMapper extends BaseMapper<Product> {
    @Select("SELECT * FROM product WHERE category= #{categoryId};")
    List<Product> getProductListByCategory(String categoryId);
    @Select("SELECT * FROM product WHERE productId=#{productId};")
    Product getProduct(String productId);
    @Select("SELECT productid FROM item WHERE itemid=#{itemId};")
    String getProductId(String itemId);
    @Select("SELECT * FROM product WHERE name=#{name};")
    Product getProductByname(String name);
    @Select("SELECT * FROM product WHERE name LiKE #{keywords};")
    List<Product> searchProductList(String keywords);
    @Select("SELECT productid AS productId,\n" +
            "                      category AS categoryId,name,descn\n" +
            "                        FROM product;")
    List<Product> getallproduct();
    @Delete("DELETE FROM product WHERE productid = #{productid};")
    void deleteProduct(String productid);
    @Insert("INSERT INTO product VALUES (#{productId},#{category},#{name},#{descn});")
    void insertProduct(Product product);
    @Select("SELECT * FROM product WHERE productid LiKE #{keywords};")
    List<Product> searchProduct(String keywords);
    @Update(" UPDATE product SET productid = #{productId}, category = #{category},name = #{name},descn=#{descn} WHERE productid = #{productId};")
    void updateProduct(Product product);
}
